/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-09-13 17:21:21
 * @LastEditors: swc
 * @LastEditTime: 2023-12-30 10:37:18
 */
import { ifs, ts } from '@/services';

import { N_oSetupPanel } from '@/types';

class T_cmd {
  // 主组件箱
  private compBox: ifs.I_compBox;

  // 主组件ID
  private compID: string;

  private compName: string;

  // 主组件实例
  private self: any;
  // 主组refs

  private TCoordination: ifs.I_compCoordination = null;

  private toolbarStatusBak: any = null;

  // 主组件created里初始化
  public init(self: any, compBoxInfo: ifs.I_compBoxInfo) {
    this.self = self;
    this.compBox = compBoxInfo.TcompBox;
    this.compID = compBoxInfo.compID;
    this.compName = self.G_compName;
  }

  // 构建组件协作处理类
  public newTcompCoordination(conf: any) {
    // 组件调度
    this.TCoordination = new ts.T_compCoordination(
      conf.name,
      conf.messageConfig,
      {
        setTempToolbarStatusDisabled: (
          p: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
        ) => {
          this.setTempToolbarStatusDisabled(p);
        },
        setTempToolbarStatusUnDisabled: (
          p: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
        ) => {
          this.setTempToolbarStatusUnDisabled(p);
        },
        cleanSubCompData: (
          p: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
        ) => {
          this.self.cleanSubCompData(p);
        },
        setMask: (p: boolean) => {
          this.self.isMask = p;
        }
      }
    );
  }

  // 处理组件协调
  public receEventCoordination(
    m: N_oSetupPanel.N_comps.I_eventCoordinationMsg
  ) {
    this.TCoordination.receEventCoordination(m)
      .then(([b, msg]) => {})
      .catch(msg => {
        console.error(msg);
        // this.self.$msg(msg);
      });
  }

  private setTempToolbarStatusDisabled(
    p: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
  ) {}

  private setTempToolbarStatusUnDisabled(
    p: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
  ) {}

  // 处理组件协调
  public sendEventCoordination(
    type: N_oSetupPanel.N_comps.T_eventCoordinationToolbar
  ) {
    const r = this.TCoordination.sendEventCoordination(type, this.self.$bus)
      .then(([b, msg]) => {})
      .catch(msg => {
        console.error(msg);
        // this.self.$msg(msg);
      });
  }
  // // 获取打开功能参数
  // public getOpenFunNameParams(
  //   p: N_oRefComp.I_refComp[],
  //   filter: object
  // ): ifs.I_return<N_oRefComp.I_openFunParams> {
  //   const result = new ts.T_return<N_oRefComp.I_openFunParams>();
  //   if (Tsrv.utils.noValue(p) || Tsrv.utils.noValue(filter)) {
  //     result.errmsg = Tsrv.getI18nByValue('打开功能参数空');
  //     return result;
  //   }

  //   Promise.all(
  //     p.map(e => {
  //       Tsrv.getData;
  //     })
  //   )
  //     .then(res => {})
  //     .catch(e => {
  // console.error('请求数据出错',e)
  //       result.errmsg = Tsrv.getI18nByValue('请求数据出错');
  //     });

  //   // result.setReturnData('openFunParams',?)
  //   return result;
  // }
}
interface I_cmd extends T_cmd {}
export { I_cmd, T_cmd };
